package 算法.leetcode.offer;

import java.util.Arrays;

/**
 * @author lchenglong
 * @date 2022/4/21
 */
public class Offer66 {

    public static void main(String[] args) {
        Offer66 instance = new Offer66();
        int[] ans = instance.constructArr(new int[]{1, 2, 3, 4, 5});
        System.out.println(Arrays.toString(ans));
    }
    public int[] constructArr(int[] a) {
        if (a.length == 0) return new int[0];
        int len = a.length;
        int[] b = new int[len];
        b[0] =1;
        // b[i] 表示 a[0...i-1]的乘积
        for (int i=1;i<len;i++) {
            b[i] = b[i-1] *a[i-1];
        }
        // tmp 表示a[i...n-1]的乘积
        int tmp=1;
        for (int i= len-1;i>=0;i--){
            b[i] = b[i] * tmp;
            tmp = tmp * a[i];

        }
        return b;
    }
}
